package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CollectionMemberInfoBean;
import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.MchMemberInfoBean;
import com.shop2cn.iapi.member.parameter.MchMemberInfoResp;
import com.shop2cn.iapi.member.service.MchMemberInfoCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.mchCreateCsBean;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.cs_info;
import com.ymttest.database.model.godmember.Member;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*商家会员详情
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MchMemberInfo{
	private static MchMemberInfoBean mchmemberinfoBean;
	private static MchMemberInfoCall mchmemberinfoCall;
	GodMemberWapper GodMemberWapper;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家会员详情");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		mchmemberinfoBean=new MchMemberInfoBean();
		mchmemberinfoCall=new MchMemberInfoCall();
		GodMemberWapper=new GodMemberWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(mchmemberinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchMemberInfo_001() {
		Logger.start(true,"商家会员详情获取成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String remark=TestDataManager.getRandomIp();
			GodMemberService.SetMemberRemarkCall(shopid, memid, remark);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(mobile,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,MchMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(remark,MchMemberInfoResp.getRemark(), "验证remark");
			Logger.verifyNotNull(MchMemberInfoResp.getRegisterTime(), "验证getRegisterTime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchMemberInfo_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			mchmemberinfoBean.setMemberId("1");
//			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();		
			Logger.verifyEquals("400", mchmemberinfoCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchMemberInfo_003() {
		Logger.start(true,"不输入memberid失败");
		try {
//			mchmemberinfoBean.setMemberId("1");
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();		
			Logger.verifyEquals("400", mchmemberinfoCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchMemberInfo_004() {
		Logger.start(true,"shopid和memberid不匹配失败");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid+1);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();		
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");	
			Logger.verifyEquals(null,mchmemberinfoCall.getMchMemberInfoResp().getMemberId(), "验证不会出数据");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchMemberInfo_005() {
		Logger.start(true,"积分-购买次数-累计消费金额-上次消费时间结果查询");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			Long orderid=Long.valueOf(TestDataManager.getRandomNum(10));
			String sqOrderRmbAmount="100";
			GodMemberService.processOrderPay(userId, shopid, orderid, sqOrderRmbAmount);
			
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(5,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(null,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,MchMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(5,MchMemberInfoResp.getAvailablePoints(), "验证getAvailablePoints");
			Logger.verifyEquals(5,MchMemberInfoResp.getTotalPoints(), "验证getTotalPoints");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//这个需要后续加mock 先业务验证
	public void Tc_MchMemberInfo_006() {
		Logger.start(true,"最近一个月消费-最近收货地址聚合查询成功");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchMemberInfo_007() {
		Logger.start(true,"商家会员详情获取成功,包含会员收集信息");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			CollectionMemberInfoBean collectionmemberinfoBean=new CollectionMemberInfoBean();
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setRealName("rname");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setWechatName("wxname");
			GodMemberService.collectionmemberinfoCall(collectionmemberinfoBean);
			
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(null,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(collectionmemberinfoBean.getSex(),MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(collectionmemberinfoBean.getWechatName(),MchMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(collectionmemberinfoBean.getRealName()
					,MchMemberInfoResp.getRealName(), "验证getRealName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchMemberInfo_008() {
		Logger.start(true,"商家会员详情获取成功,包含手机号");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(mobile,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,MchMemberInfoResp.getWechatName(), "验证getWechatName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchMemberInfo_009() {
		Logger.start(true,"商家会员详情获取成功-包含积分");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			Integer points=10;
			GodMemberService.sendPoints(memid, shopid, points);
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(points,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(null,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,MchMemberInfoResp.getWechatName(), "验证getWechatName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchMemberInfo_010() {
		Logger.start(true,"商家会员详情获取成功-开启需要手机认证后RegisterTime为绑定手机时间");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			GodMemberService.setCollectionMobile(shopid, true);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String remark=TestDataManager.getRandomIp();
			GodMemberService.SetMemberRemarkCall(shopid, memid, remark);
			
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(null,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,MchMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(remark,MchMemberInfoResp.getRemark(), "验证remark");
			Logger.verifyIsNull(MchMemberInfoResp.getRegisterTime(), "验证getRegisterTime");
			
			GodMemberService.bindMobile(shopid, userId, TestDataManager.getPhoneNum());
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			Logger.verifyNotNull(mchmemberinfoCall.getMchMemberInfoResp().getRegisterTime(), "验证getRegisterTime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchMemberInfo_011() {
		Logger.start(true,"商家会员详情获取成功-新增返回绑定客服信息");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberService.setInvitationCodeCall(shopid, true, 1);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String remark=TestDataManager.getRandomIp();
			GodMemberService.SetMemberRemarkCall(shopid, memid, remark);
			
			mchmemberinfoBean.setMemberId(memid);
			mchmemberinfoBean.setShopId(shopid);
			mchmemberinfoCall.setData(mchmemberinfoBean);
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			
			MchMemberInfoResp MchMemberInfoResp=mchmemberinfoCall.getMchMemberInfoResp();
			GodMemberWapper GodMemberWapper=new GodMemberWapper();
			Member mem = GodMemberWapper.selectMemberByMemberid(MchMemberInfoResp.getMemberId()).get(0);
			Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
			Logger.verifyEquals(0,MchMemberInfoResp.getAvailablePoints(), "验证AvailablePoints");
			Logger.verifyEquals(usercreateBean.getNickname(),MchMemberInfoResp.getNickName(), "验证getNickName");
			Logger.verifyEquals(usercreateBean.getLogoUrl(),MchMemberInfoResp.getAvatar(), "验证getAvatar");
			Logger.verifyEquals(null,MchMemberInfoResp.getMobile(), "验证getMobile");
			Logger.verifyEquals(null,MchMemberInfoResp.getSex(), "验证getSex");
			Logger.verifyEquals(null,MchMemberInfoResp.getWechatName(), "验证getWechatName");
			Logger.verifyEquals(remark,MchMemberInfoResp.getRemark(), "验证remark");
			Logger.verifyIsNull(MchMemberInfoResp.getRegisterTime(), "验证getRegisterTime");
			mchCreateCsBean mchCreateCsBean = GodmchManageCallService.initMchCreateCsBean(shopid);
			mchCreateCsBean.setTemplateId(11);
			GodmchManageCallService.mchCreateCsCall(mchCreateCsBean);
			cs_info csi2=new DefGodMchWapper().selectCsInfoByMchId(mchCreateCsBean.getMchId()).get(0);
			GodMemberService.bindMobile(shopid, userId, TestDataManager.getPhoneNum(),csi2.getCsId());
			mchmemberinfoCall.callService();			
			Logger.verifyEquals("200", mchmemberinfoCall.getString("code"), "验证code");
			Logger.verifyNotNull(mchmemberinfoCall.getMchMemberInfoResp().getRegisterTime(), "验证getRegisterTime");
			Logger.verifyEquals(mchCreateCsBean.getLoginId()
					, mchmemberinfoCall.getMchMemberInfoResp().getCsAccount(),  "验证getCsAccount");
			Logger.verifyEquals(mchCreateCsBean.getTitle() , mchmemberinfoCall.getMchMemberInfoResp().getCsName(),  "验证getCsName");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}